package org.sbbs.security.dao.hibernate;

import java.util.List;

import org.sbbs.base.dao.hibernate.BaseDAOImpl;
import org.sbbs.security.dao.UrlResourceDao;
import org.sbbs.security.model.UrlResource;
import org.springframework.stereotype.Repository;

import com.googlecode.genericdao.search.ISearch;
import com.googlecode.genericdao.search.Search;

@Repository("urlResourceDao")
public class UrlSecurityResourceDaoHibernate extends BaseDAOImpl<UrlResource, Long> implements
		UrlResourceDao {

	@Override
	public void clearUrlResourceRepo() {
		String hql = "delete from UrlResource";
		//this.getHibernateTemplate().bulkUpdate(hql);
		this.getSession().createQuery(hql).executeUpdate();

	}

	public List getDistinctNameSapces() {
		Search s = new Search();
		s.addField("nameSpace");
		s.setDistinct(true);
		s.addSortAsc("nameSpace");
		s.setResultMode(ISearch.RESULT_SINGLE);
		return this.search(s);
	}
	
	
	public List getByNameSpace(String ns){
		Search s = new Search();
		s.addFilterEqual("nameSpace", ns);
		s.addSortAsc("url");
		
		return this.search(s);
		
	}
}
